//
//  MPBaseNavController.swift
//  MPSinaWeibo
//
//  Created by DaVinci on 16/4/9.
//  Copyright © 2016年 DaVinci. All rights reserved.
//

import UIKit

class MPBaseNavController: UINavigationController,UIGestureRecognizerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        
        navigationBar.setBackgroundImage(UIImage(named: "navBarImage"), forBarMetrics: .Default)
        
        //MARK:设置手势滑动代理
        self.interactivePopGestureRecognizer?.delegate = self
    }
    
    override func pushViewController(viewController: UIViewController, animated: Bool) {
        
        if childViewControllers.count > 0 {
            
            var backTitle = "返回"
            
            if childViewControllers.count == 1{
            
                backTitle = childViewControllers.first?.title ?? ""
            }
            
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(imageName: "navigationbar_back_withtext", title: backTitle, target: self, action: "back")
            viewController.hidesBottomBarWhenPushed = true

        
        }
        
        //viewController.view.backgroundColor = UIColor.whiteColor()
        
        super.pushViewController(viewController, animated: true)
    }
    
    @objc private func back(){
    
        self.popViewControllerAnimated(true)
    }
    
    
    //MARK:滑动代理方法
    func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
        
        return childViewControllers.count != 1
    }
}
